<?php
declare (strict_types=1);

namespace app\course\service\payment;

use app\common\service\BaseService;
use app\course\logic\payment\PaymentOrder;
use app\user\logic\user\Cart as CartLogic;
use think\facade\{Request};
use think\annotation\Inject;
use think\Response;

/**
 * 订单支付接口类
 */
class Payment extends BaseService
{
    /**
     * @Inject()
     * @var PaymentOrder
     */
    protected $order;

    /**
     * 切换卡券更新积分选择
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-08-30
     */
    public function orderCourseCredit(): Response
    {
        $param = Request::get();
        $data  = $this->order->orderCourseCredit($param);

        return static::parseToData($data, 1, '获取成功');
    }

    /**
     * 课程直接购买订单页
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-26
     */
    public function orderCourseFetch(): Response
    {
        $param = Request::get();
        $data  = $this->order->orderCourseFetch($param);

        return static::parseToData($data, 1, '获取成功');
    }

    /**
     * 课程直接购买生成订单
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-23
     */
    public function orderCourseCreate(): Response
    {
        $param = Request::post();
        $data  = $this->order->createCourseOrder($param);

        return static::parseToData($data, 1, '订单提交成功');
    }

    /**
     * 课时直接购买订单页
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-26
     */
    public function orderSectionFetch(): Response
    {
        $param = Request::get();
        $data  = $this->order->orderSectionFetch($param);

        return static::parseToData($data, 1, '获取成功');
    }

    /**
     * 课时直接购买生成订单
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-23
     */
    public function orderSectionCreate(): Response
    {
        $param = Request::post();
        $data  = $this->order->createSectionOrder($param);

        return static::parseToData($data, 1, '订单提交成功');
    }

    /**
     * 购物车 - 页面
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-27
     */
    public function cartFetch(): Response
    {
        $data = app(CartLogic::class)->cartFetch();

        return static::parseToData($data, 1, '获取成功');
    }

    /**
     * 购物车 - 添加到购物车
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-30
     */
    public function cartAdd(): Response
    {
        $param = Request::post();
        $data  = app(CartLogic::class)->cartAdd($param);

        return static::parseToData($data, 1, '添加成功');
    }

    /**
     * 购物车 - 移除商品
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-30
     */
    public function cartDelete(): Response
    {
        $param = Request::put();
        $data  = app(CartLogic::class)->cartDelete($param);

        return static::parseToData($data, 1, '移除成功');
    }

    /**
     * 购物车订单页渲染数据
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-21
     */
    public function orderCartFetch(): Response
    {
        $param = Request::get();
        $data  = $this->order->orderFetchCart($param);

        return static::parseToData($data, 1, '获取成功');
    }

    /**
     * 切换卡券更新积分选择
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-08-30
     */
    public function orderCartCredit(): Response
    {
        $param = Request::get();
        $data  = $this->order->orderCartCredit($param);

        return static::parseToData($data, 1, '获取成功');
    }

    /**
     * 购物车生成订单
     * Author   亓官雨树<lucky.max@foxmail.com>
     * Date 2020-04-23
     */
    public function orderCartCreate(): Response
    {
        $param = Request::post();
        $data  = $this->order->orderCreateCart($param);

        return static::parseToData($data, 1, '订单提交成功');
    }

}
